#coding:gbk
def readlog(filename):
    f = open(filename,'r')
    content = f.readlines()
    f.close()
    ls_lst = []
    lsh_last = ''
    sj_tmp = []
    for line in content:
        sj,ywmc,jydm,lsh = line.split(']')[0].split('-')
        sj = sj.strip('[')
        
        tmp_dic = {'lsh':lsh,'jysj':sj,'ywdm':jydm,'description':ywmc,'jgdm':'jgdm','khzh':'khzh','shzh':'shzh','fse':'fse','czbz':'czbz','zt':'zt'}
        if lsh_last == '':
            lsh_last = lsh
        elif lsh_last != lsh:
            try:
                tmp_dic['zt'] = int(sj_tmp[-1]) - int(sj_tmp[0])
            except:
                print sj_tmp
            lsh_last = lsh
            ls_lst.append(tmp_dic)
            sj_tmp = []
        else:
            sj_tmp.append(sj)
    return ls_lst
#print readlog('mcam.2018-05-25.log')
def getlogfromfile(filename,lsh):
    f = open(filename,'r')
    content = f.readlines()
    f.close()
    cont = []
    for line in content:
        sj,ywmc,jydm,lsh_tmp = line.split(']')[0].split('-')
        if lsh == lsh_tmp:
            cont.append(line)
    return cont
